package io;

import java.io.*;

public class DataOutputStreamDemo {

    public static void main(String[] args) throws IOException {

        //  先写
        OutputStream out = new FileOutputStream("test.txt");
        DataOutputStream dataOutputStream = new DataOutputStream(out);
        dataOutputStream.writeInt(97);
        dataOutputStream.writeDouble(5.6);
        dataOutputStream.writeUTF("abc温健");
        dataOutputStream.close();
        out.close();

        // 后读
        InputStream in = new FileInputStream("test.txt");
        DataInputStream dataInputStream = new DataInputStream(in);
        System.out.println(dataInputStream.readInt());
        System.out.println(dataInputStream.readDouble());
        System.out.println(dataInputStream.readUTF());
        dataInputStream.close();
        in.close();

    }
}
